#include "TIM.h"
#include "stm32f10x.h"


void init_tim(void){


    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
    
    //RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
    
    TIM_InternalClockConfig(TIM2);
    
    TIM_TimeBaseInit(TIM2,&(TIM_TimeBaseInitTypeDef){
    
        .TIM_Prescaler= 7200,
        .TIM_CounterMode = TIM_CounterMode_Up,
        .TIM_Period = 100,
        .TIM_ClockDivision=TIM_CKD_DIV1
    
    });
    
    TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
    
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    
    NVIC_Init(&(NVIC_InitTypeDef){
    
        .NVIC_IRQChannel = TIM2_IRQn,
        .NVIC_IRQChannelPreemptionPriority=2,
        .NVIC_IRQChannelSubPriority=2,
        .NVIC_IRQChannelCmd= ENABLE
    
    });

    TIM_Cmd(TIM2,ENABLE);
}

